<!-- 业务主管理 -->
<template>
    <div class="rightCenter">
        <div class="listTop">
            <div class="listTopAddBut" @click="addClick()">
                添 加
            </div>
            <div class="listTopInpBox">
                <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div>
                <input class="listTopInp" type="text" v-model='nameVal' oninput='searchFun' placeholder="搜索名称">
            </div>
        </div>
        <ul class="listUl">
            <li class="listLi fristLI">
                <div class="listDiv listOne">
                    业务主ID
                </div>
                <div class="listDiv listTwo">
                    业务主名称
                </div>
                <div class="listDiv listThree">
                    业务主简介
                </div>
                <div class="listDiv listFour">
                    操作
                </div>
            </li>
            <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
                <div class="listDiv listOne">
                    {{item.id}}
                </div>
                <div class="listDiv listTwo">
                    {{item.name}}
                </div>
                <div class="listDiv listThree">
                    {{item.desc }}
                </div>
                <div class="listDiv listFour">
                    <div class="edit buttonBox" @click='editClick(index)'>
                        编辑
                    </div>
                    <div class="delect buttonBox" @click='delectClick(index)'>
                        删除
                    </div>
                </div>
            </li>
        </ul>
        <div class="paging">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
            </el-pagination>
        </div>
        <!-- 删除弹框 -->
        <div class="fixedBox" v-show='delectBocShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        确认要删除该角色吗？
                    </div>
                    <div class="popuplistBoxTopBut" @click='delectCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='delectOkClick()'>
                        确 认
                    </div>
                    <div class="popupCheckFail" @click='delectCancelClick()'>
                        取 消
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import taskRequest from "../../assets/task";
export default {
  data() {
    return {
      nameVal: "", //所搜
      dataList: [],
      currentPage: 10, //每页条数
      pageSize: 1, //页码
      totalVal: 0, //总数量
      delectBocShow: false,
      editIndex: ""
    };
  },
  filters: {},
  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "业务主管理") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    } else {
      this.$router.push({
        path: "/login"
      });
      sessionStorage.clear();
      self.$message("暂无权限");
      return;
    }
    self.getList();
  },
  watch: {},
  mounted() {},
  methods: {
    //搜索
    searchFun() {},
    //获取列表
    getList() {
      let self = this;
      taskRequest
        .providerListFun({
          page: self.pageSize,
          size: self.currentPage
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.totalVal = data.data.total;
            if (data.data.records) {
              self.dataList = data.data.records;
            }
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
    },
    //分页 - 每页条数
    handleSizeChange(val) {
      this.currentPage = val;
      this.getList();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageSize = val;
      this.getList();
    },
    //添加
    addClick() {
      this.$router.push({
        path: "/home/business/edit?button=add"
      });
    },
    // 编辑
    editClick(index) {
      this.$router.push({
        path: `/home/business/edit?button=edit&id=${this.dataList[index].id}`
      });
    },
    //删除
    delectClick(index) {
      this.delectBocShow = true;
      this.editIndex = index;
    },
    //确认删除
    delectOkClick() {
      let self = this;
      taskRequest
        .providerDeleteFun({
          providerId: self.dataList[self.editIndex].id
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.$message({
              showClose: true,
              message: "删除成功",
              type: "success"
            });
            self.getList();
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      this.delectBocShow = false;
    },
    //取消删除
    delectCancelClick() {
      this.delectBocShow = false;
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 20%;
}

.listTwo {
  width: 25%;
}

.listThree {
  width: 30%;
}

.listFour {
  width: 25%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.edit {
  background: #279de2;
  margin: 0 4px;
}

.delect {
  background: #ed4a47;
  margin: 0 4px;
}
</style>